package org.goldenport.g3.messages.view

import java.io._
import org.goldenport.util.{QSymbol, QSymbolSet}
import org.goldenport.g3.G3Command
import org.goldenport.g3.messages._
import org.goldenport.g3.messages.query.RecordQuery

/**
 * @since   Aug. 27, 2010
 * @version Sep. 18, 2010
 * @author  ASAMI, Tomoharu
 */
abstract class ViewCommand(uris: QSymbolSet) extends G3Command(uris.head.path) {
  def this(uri: QSymbol) = this(QSymbolSet(uri))
}

/**
 * Fetch or Query view instances by ids or condition.
 */
class FetchView(uri: QSymbol, val ids: List[AnyRef]) extends ViewCommand(uri) {
}

class QueryView(val query: RecordQuery) extends ViewCommand(query.uris) {
}

class QueryViewExpression(uri: QSymbol, val expression: Expression) extends ViewCommand(uri) {
}

object Fetch {
  def apply(uri: QSymbol, id: Any) = new FetchView(uri, List(id.asInstanceOf[AnyRef]))

  def apply(uri: QSymbol, ids: List[AnyRef]) = new FetchView(uri, ids)
}

object Query {
  def apply(query: RecordQuery) = new QueryView(query)

  def apply(uri: QSymbol, expression: Expression) = new QueryViewExpression(uri, expression)
}
